package org.ITschool.support.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.omg.CORBA.PUBLIC_MEMBER;

import net.sf.json.JSONObject;

public class StatusBean {
    private int statu;
    private String status_c;
	public int getStatu() {
		return statu;
	}
	public void setStatu(int statu) {
		this.statu = statu;
	}
	public String getStatus_c() {
		return status_c;
	}
	public void setStatus_c(String statusC) {
		status_c = statusC;
	}
    public static void set_success_status(HttpServletRequest request,String content){
    	StatusBean status=new StatusBean();
    	status.setStatu(1);
    	status.setStatus_c(content);
    	request.setAttribute("status", status);
    }
    public static void set_defaile_status(HttpServletRequest request,String content){
    	StatusBean status=new StatusBean();
    	status.setStatu(0);
    	status.setStatus_c(content);
    	request.setAttribute("status", status);
    }
   public static void putsuccess_json(HttpServletResponse response,String msg){
	      PrintWriter out;
		try {
			 response.setCharacterEncoding("utf-8");
			out = response.getWriter();
			 JSONObject json=new JSONObject();
			 json.put("statusCode", "200");
			 json.put("message", msg);
			 json.put("navTabId", "");
			 json.put("rel", "");
			 json.put("callbackType", "");
			 json.put("forwardUrl", "");
			 json.put("confirmMsg", "");
			 out.print(json);
			 out.flush();
			 out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	      
	  
   }
   public static void putdefaile_json(HttpServletResponse response,String msg){
	   try {
		   response.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter();
		JSONObject json=new JSONObject();
		 json.put("statusCode", "300");
		 json.put("message", msg);
		 json.put("navTabId", "");
		 json.put("rel", "");
		 json.put("callbackType", "");
		 json.put("forwardUrl", "");
		 json.put("confirmMsg", "");
		 out.print(json);
		 out.flush();
		 out.close();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	 
		
   }
   public static void putTimeout(HttpServletResponse response,String msg){
	   try {
		   response.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter();
		JSONObject json=new JSONObject();
		 json.put("statusCode", "301");
		 json.put("message", msg);
		 json.put("navTabId", "");
		 json.put("rel", "");
		 json.put("callbackType", "");
		 json.put("forwardUrl", "");
		 json.put("confirmMsg", "");
		 out.print(json);
		 out.flush();
		 out.close();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
   }
}
